package org.example.psn.core.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.psn.core.entity.Person;
import org.example.psn.core.mapper.PersonMapper;
import org.example.psn.core.service.IPersonService;
import org.example.system.common.constant.BaseConstant;
import org.example.system.common.dto.UserAuthDto;
import org.example.system.common.dto.psn.UserInfoDto;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * <p>
 * 用户信息 服务实现类
 * </p>
 *
 * @author Joey
 * @since 2021-05-11
 */
@Service
public class PersonServiceImpl extends ServiceImpl<PersonMapper, Person> implements IPersonService {
    @Resource
    PersonMapper personMapper;

    @Cacheable(value = "cache1",key = "'psn:person:queryNamesById_'+#psnIds")
    @Override
    public String queryNamesById(String psnIds) {
        if(StrUtil.isEmpty(psnIds)){
            return BaseConstant.STR_EMPTY;
        }
        List<String> idList = StrUtil.split(psnIds, BaseConstant.SPITS_CHAR1);
        QueryWrapper qw = new QueryWrapper();
        qw.select("psnName");
        qw.in("id",idList);
        List<Person> psnList = personMapper.selectList(qw);
        if(psnList==null || psnList.size()==0){
            return BaseConstant.STR_EMPTY;
        }
        Set<String> nameSet = new HashSet<>(psnList.size());
        for(Person item : psnList){
            nameSet.add(item.getPsnName());
        }
        return CollUtil.join(nameSet, BaseConstant.SPITS_STR1);
    }

    @Cacheable(value = "cache1",key = "'psn:queryAuthInfoByToken_'+#jwt")
    @Override
    public UserAuthDto queryAuthInfoByToken(String jwt) {
        return null;
    }

    @Cacheable(value = "cache1",key = "'psn:queryPersonById_'+#psnId")
    @Override
    public UserInfoDto queryPersonById(Long psnId) {
        return null;
    }
}
